<template>
  <div id='crgResultComp'>
    <Splitpanes style="height:100%;" horizontal>
      <Pane v-show="(isChk && yqpxResultList.length>0 )|| isYqpy" :size="20">
        <div>
          <vxe-toolbar class-name="bg-gray solid-top">
            <template #tools>
              <div class="flex justify-content-end padding-right-xs text-bold">
                <span>血培养结果</span>
              </div>
            </template>
          </vxe-toolbar>
        </div>
        <div class='crgResultCompTable' :style='{ height: isChildren ? "calc(100% - 40px)" : "calc(100% - 40px)" }'>
          <vxe-table ref='ASTResultCompTable' v-loading='loading' border height='auto' :data='yqpxResultList' :row-config='{ isCurrent: true, isHover: true }' :mouse-config='{ selected: true }' :keyboard-config='{ isArrow: true, isTab: true, isEdit: false }' resizable show-overflow>
            <vxe-column type="seq" width="30"></vxe-column>
            <vxe-column field="culMediumNa" title="培养瓶名称" align="center" show-overflow></vxe-column>
            <vxe-column field="samplingSiteNa" title="采样部位" align="center" show-overflow></vxe-column>
            <vxe-column field="result" title="培养结果" align="center" show-overflow>
              <template #default="{ row }">
                <span>{{IsEmpty(row.resultThreeDays)?row.result:row.resultThreeDays}}</span>
              </template>
            </vxe-column>
            <vxe-column field="isPositive" title="是否阳性" align="center" show-overflow>
              <template #default="{ row }">
                <span>{{ getYesOrNo(row.isPositive) }}</span>
              </template>
            </vxe-column>
            <vxe-column field="expoTime" title="报阳时长" align="center" show-overflow>
              <template #default="{ row }">
                <span>{{IsEmpty(row.resultThreeDays)?row.expoTime:''}}</span>
              </template>
            </vxe-column>
            <vxe-column field="isAlarm" title="是否危急值" align="center" show-overflow>
              <template #default="{ row }">
                <span>{{ getYesOrNo(row.isAlarm) }}</span>
              </template>
            </vxe-column>
            <vxe-column field="alarmText" title="危急值描述" align="center" show-overflow></vxe-column>
            <vxe-column field="isPollute" title="是否污染" align="center" show-overflow>
              <template #default="{ row }">
                <span>{{ getYesOrNo(row.isPollute) }}</span>
              </template>
            </vxe-column>
            <vxe-column field="specialDesc" title="描述" align="center" show-overflow></vxe-column>
          </vxe-table>
        </div>
      </Pane>
      <Pane v-show="(isChk && stainingResultList.length>0) || isShowStaining" :size="15">
        <div>
          <vxe-toolbar class-name="bg-gray solid-top">
            <template #tools>
              <div class="flex justify-content-end padding-right-xs text-bold">
                <span>染色结果</span>
              </div>
            </template>
          </vxe-toolbar>
        </div>
        <div class='crgResultCompTable' :style='{ height: isChildren ? "calc(100% - 40px)" : "calc(100% - 40px)" }'>
          <vxe-table ref='stainingResultTable' v-loading='loading' border height='auto' :data='stainingResultList' :row-config='{ isCurrent: true, isHover: true }' :mouse-config='{ selected: true }' :keyboard-config='{ isArrow: true, isTab: true, isEdit: false }' resizable show-overflow>
            <vxe-column type="seq" width="30"></vxe-column>
            <vxe-column field="isolateNumber" title="类型" width="80" show-overflow>
              <template #default="{ row }">
                <span>{{ getIsStaticStatusDesc(row.handleType) }}</span>
              </template>
            </vxe-column>
            <vxe-column field="stainingMethNa" title="操作内容" show-overflow>
              <template #default="{ row }">
                <span>{{ row.descText }}</span>
              </template>
            </vxe-column>
            <vxe-column field="createTime" title="操作时间" width="120" show-overflow></vxe-column>
            <vxe-column field="userName" title="操作人" width="120" show-overflow></vxe-column>

          </vxe-table>
        </div>
      </Pane>
<!--      系统参数展示培养培养前提下 审核并且有数据 或者是 未审核,处于培养观察节点 进行展示-->
      <Pane v-show="((isChk && pygcResultList.length>0) || ispeiyang) && pygcShow" :size="30">
        <div>
          <vxe-toolbar class-name="bg-gray solid-top">
            <template #tools>
              <div class="flex justify-content-end padding-right-xs text-bold">
                <span>培养/镜检</span>
              </div>
            </template>
          </vxe-toolbar>
        </div>
        <div class='crgResultCompTable' :style='{ height: isChildren ? "calc(100% - 40px)" : "calc(100% - 40px)" }'>
          <vxe-table ref='ASTResultCompTable' v-loading='loading' border height='auto' :data='pygcResultList'
                     :row-config='{ isCurrent: true, isHover: true }'
                     :mouse-config='{ selected: true }' :keyboard-config='{ isArrow: true, isTab: true, isEdit: false }' resizable
                     show-overflow>
            <vxe-column type="seq" width="30"></vxe-column>
            <vxe-column field="morphologyName" title="结果描述"  align="center" show-overflow></vxe-column>
            <vxe-column field="strainCount" title="菌落计数"  align="center" show-overflow></vxe-column>
            <vxe-column field="bacRate" title="菌群比例"  align="center" show-overflow></vxe-column>
            <vxe-column field="experiment" title="生化实验"  align="center" show-overflow></vxe-column>
            <vxe-column field="isAlarm" title="是否危急值"  align="center" show-overflow>
              <template #default="{ row }">
                <span>{{ getYesOrNo(row.isAlarm) }}</span>
              </template>
            </vxe-column>
            <vxe-column field="alarmText" title="危急值描述"  align="center" show-overflow></vxe-column>
          </vxe-table>
        </div>
      </Pane>
      <Pane v-show="isChk || isJingJian" :size="15">
        <div>
          <vxe-toolbar class-name="bg-gray solid-top">
            <template #tools>
              <div class="justify-start padding-right-xs text-bold">
                <span>微生物结果</span>
              </div>
            </template>
          </vxe-toolbar>
        </div>
        <div class='crgResultCompTable' :style='{ height: isChildren ? "calc(100% - 40px)" : "calc(100% - 40px)" }'>
          <vxe-table ref='identificationResultTable' v-loading='loading' border height='auto' :data='testResultList' class="mytable-scrollbar" @cell-click='identificationResultRowClick' :row-config='{ isCurrent: true, isHover: true }' :mouse-config='{ selected: true }' :keyboard-config='{ isArrow: true, isTab: true, isEdit: false }' resizable show-overflow>
            <vxe-column width="10" class-name="cell-bgColor">
              <template #default="{ row }">
                <div :style="{ backgroundColor: row.isWkf ? '#409eff' : '', height: '100%' }"></div>
              </template>
            </vxe-column>
            <vxe-column field="germNo" title="编号" width="30"></vxe-column>
            <vxe-column field="germNa" title="结果"></vxe-column>
            <vxe-column field="testResult" title="结果描述"></vxe-column>
            <vxe-column field="resiPhenNa" title="耐药表型"></vxe-column>
            <vxe-column field="urinColoCount" title="菌落计数" width="80"></vxe-column>
            <vxe-column field="infeSiteNa" title="感染部位" width="60"></vxe-column>
            <vxe-column field="operateDate" title="操作时间" width="120"></vxe-column>
            <vxe-column field="operateUserNo" title="操作人" width="60"></vxe-column>
          </vxe-table>
        </div>
      </Pane>
      <Pane v-show="isChk" :size="50">
        <div>
          <vxe-toolbar class-name="bg-gray solid-top">
            <template #tools>
              <div class="flex justify-content-end padding-right-xs text-bold">
                <span>药敏结果</span>
              </div>
            </template>
          </vxe-toolbar>
        </div>
        <div class='crgResultCompTable' :style='{ height: isChildren ? "calc(100% - 40px)" : "calc(100% - 40px)" }'>
          <vxe-table ref='ASTResultCompTable' v-loading='loading' border height='auto' :data='drugTestResultList' class="mytable-scrollbar" :row-config='{ isCurrent: true, isHover: true }' :mouse-config='{ selected: true }' :keyboard-config='{ isArrow: true, isTab: true, isEdit: false }' resizable show-overflow>
            <!-- <vxe-column width="10" class-name="cell-bgColor">
              <template #default="{ row }">
                <div :style="{ backgroundColor: row.isWkf ? '#409eff' : '', height: '100%' }"></div>
              </template>
            </vxe-column> -->
            <vxe-column field="isReport" title="报告" width="30" align="center">
              <template #default="{ row }">
                <vxe-checkbox v-model="row.isReport" :checked-value="1" :unchecked-value="0"></vxe-checkbox>
              </template>
            </vxe-column>
            <vxe-column field="antRecomGroupId" title="分组" width="30">
            </vxe-column>
            <vxe-column field="antNo" title="" width="35"></vxe-column>
            <vxe-column field="antNa" title="抗生素" width="110">
            </vxe-column>
            <vxe-column field="potency" title="效价" width="50"></vxe-column>
            <vxe-column field="drugTestMethNa" title="方法" width="45">
            </vxe-column>
            <vxe-column field="testResult" title="结果" width="60">
            </vxe-column>
            <vxe-column field="interpNa" title="敏感性" align="center" width="50">
            </vxe-column>
            <vxe-column field="breakPoint" title="折点" width="100">
            </vxe-column>
            <vxe-column field="isNaturlResis" title="天然耐药" width="50" align="center">
              <template #default="{ row }">
                <vxe-checkbox v-model="row.isNaturlResis" :checked-value="1" :unchecked-value="0"></vxe-checkbox>
              </template>
            </vxe-column>
            <vxe-column field="r" title="耐药" width="40" header-align="center"></vxe-column>
            <vxe-column field="i" title="中介" width="100" header-align="center"></vxe-column>
            <vxe-column field="sdd" title="SDD" width="100" header-align="center"></vxe-column>
            <vxe-column field="s" title="敏感" width="40" header-align="center"></vxe-column>
            <vxe-column field="ecoff" title="流行病学界值" width="80" header-align="center"></vxe-column>
            <vxe-column field="whonetTest" title="WhonetTest" width="80" header-align="center"></vxe-column>
            <vxe-column field="breakPointRef" title="折点范围" width="120" header-align="center"></vxe-column>
            <vxe-column field="guideline" title="指南" width="35" header-align="center"></vxe-column>
            <vxe-column field="year" title="年" width="30" header-align="center"></vxe-column>
            <vxe-column field="germCodeType" title="微生物代码类型" width="110" header-align="center"></vxe-column>
            <vxe-column field="germNo" title="微生物代码" width="65" header-align="center"></vxe-column>
            <vxe-column field="breakPointType" title="折点类型" width="50" header-align="center"></vxe-column>
            <vxe-column field="host" title="宿主" width="50" header-align="center"></vxe-column>
            <vxe-column field="infeSite" title="感染部位" width="60" header-align="center"></vxe-column>
            <vxe-column field="refTable" title="参考表" width="60" header-align="center"></vxe-column>
            <vxe-column field="refTableSeq" title="参考表序号" width="70" header-align="center"></vxe-column>
            <vxe-column field="breakPointId" title="折点编号" width="160" header-align="center"></vxe-column>
          </vxe-table>
        </div>
      </Pane>
    </Splitpanes>

  </div>
</template>
<script lang='ts' setup>
import { reactive, ref, getCurrentInstance } from 'vue';
import { formatDateTime, IsEmpty } from '@/utils/common';
import { Splitpanes, Pane } from 'splitpanes';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
let { proxy }: any = getCurrentInstance();

let isChildren = ref(false);
let isChk = ref(false);
let isShowStaining = ref(false);
let isJingJian = ref(false);
let isYqpy = ref(false);
let ispeiyang = ref(false);
let pygcShow = ref(false);
let pageIndex = ref(1);
let totalCount = ref(0);
let loading = ref(false);
let currentRowIndex = ref(0);
let testResultLoading = ref(false);
let curOrgResultObj = ref({}); //微生物鉴定结果
let testResultList = reactive([]); //微生物鉴定结果列表
let stainingResultList = reactive([]); //染色结果集合
let yqpxResultList = reactive([]); //仪器培养结果集合
let pygcResultList = reactive([]); //培养观察结果集合
let drugTestResultList = reactive([]); //药敏结果
let ASTRLoading = ref(false);

let form = reactive({
  searchValue: ''
});

//暴露属性和方法
defineExpose({
  clearData,
  initPage
});

function getYesOrNo(row) {
  if (row == 1) {
    return '是';
  } else {
    return '否';
  }
}
function getIsStaticStatusDesc(row) {
  if (row == 0) {
    return '涂片';
  } else if (row == 1) {
    return '分纯';
  } else if (row == 2) {
    return '转种';
  } else if (row == 3) {
    return '续培';
  } else {
    return '';
  }
}
function clearData() {
  testResultList.length = 0;
  drugTestResultList.length = 0;
  isShowStaining.value = false;
  isJingJian.value = false;
  isYqpy.value = false;
}
function initPage(row: any) {
  isShowStaining.value = false;
  isJingJian.value = false;
  isYqpy.value = false;
  ispeiyang.value = false;
  pygcShow.value=row.pygcShow;
  if (row.isChk === 2) {
    isChk.value = true;
    getBacTestResultList(row);
    getStainingData(row);
    getYqpyResultList(row);
    getPeiyangGuanChaResultList(row);
  } else {
    isChk.value = false;
    if (row.bacFlowNode == 'STAINING') {
      isShowStaining.value = true;
      getStainingData(row);
    }
    if (row.bacFlowNode == 'JINGJIAN') {
      isJingJian.value = true;
      getBacTestResultList(row);
    }
    if (row.bacFlowNode == 'YQPY') {
      isYqpy.value = true;
      getYqpyResultList(row);
    }
      if (row.bacFlowNode == 'PEIYANG'){
      ispeiyang.value=true;
      getPeiyangGuanChaResultList(row);
    }
  }
}
//获取染色结果
function getStainingData(row) {
  testResultLoading.value = true;
  let data = {
    rptGroup: row.rptGroup,
    sampleda: formatDateTime(row.sampleda, 'yyyy-MM-dd 00:00:00'),
    sampleNo: row.sampleNo,
    isPushSecReport: 1
  } as any;
  stainingResultList.length = 0; /**放入数据前清空数据*/
  const url = '/api/bac/bac-staining-result/findBacStainingResultListBySampleNo';
  proxy.$http
    /**注意此处的数据条数*/
    .get(url, { params: data })
    .then((res: any) => {
      stainingResultList.push(...res.data);
      loading.value = false;
    })
    .catch((err: any) => {
      loading.value = false;
      VxeMessage('获取染色结果列表数据异常', VxeNotifyType.error);
    });
}

//仪器培养结果
function getYqpyResultList(row) {
  testResultLoading.value = true;
  let data = {
    rptGroup: row.rptGroup,
    sampleda: formatDateTime(row.sampleda, 'yyyy-MM-dd 00:00:00'),
    sampleNo: row.sampleNo,
    bacPublishStatus: 1,
    mediumType: 2
  } as any;
  yqpxResultList.length = 0; /**放入数据前清空数据*/
  const url = '/bac-blood-cultrue/findBacBloodCultrueList';
  proxy.$http
    /**注意此处的数据条数*/
    .get(url, { params: data })
    .then((res: any) => {
      yqpxResultList.push(...res.data);
      loading.value = false;
    })
    .catch((err: any) => {
      loading.value = false;
      VxeMessage('获取仪器培养结果列表数据异常', VxeNotifyType.error);
    });
}
//仪器培养结果
function getPeiyangGuanChaResultList(row) {
  testResultLoading.value = true;
  let data = {
    rptGroup: row.rptGroup,
    sampleda: formatDateTime(row.sampleda, 'yyyy-MM-dd 00:00:00'),
    sampleNo: row.sampleNo,
    bacPublishStatus: 1
  } as any;
  pygcResultList.length = 0; /**放入数据前清空数据*/
  const url = '/api/bac/bac-obser-result/findBacObserResultList';
  proxy.$http
    /**注意此处的数据条数*/
    .get(url, { params: data })
    .then((res: any) => {
      pygcResultList.push(...res.data);
      loading.value = false;
    })
    .catch((err: any) => {
      loading.value = false;
      VxeMessage('获取培养观察结果列表数据异常', VxeNotifyType.error);
    });
}

// 获取鉴定结果
function getBacTestResultList(row) {
  testResultList.length = 0;
  drugTestResultList.length = 0;

  if (!row || IsEmpty(row.id)) {
    Object.assign(curOrgResultObj, null);
    return;
  }
  Object.assign(curOrgResultObj, row);

  testResultLoading.value = true;
  const url = 'api/bac/bac-test-result/findBacTestResultList';
  const data = {
    rptGroup: row.rptGroup,
    sampleda: row.sampleda + ' 00:00:00',
    sampleNo: row.sampleNo
  };
  proxy.$http
    .get(url, { params: data })
    .then((res: any) => {
      testResultList.push(...res.data);
      identificationResultRowClick({ row: res.data[0], rowIndex: 0 }); //默认单机第一行
      testResultLoading.value = false;
    })
    .catch((err) => {
      proxy.$alert(err.data.error.message, '提示');
      testResultLoading.value = false;
    });
}
// 行点击事件
function identificationResultRowClick({ row, rowIndex }) {
  drugTestResultList.length = 0;
  if (IsEmpty(row)) {
    return;
  }
  const $table = proxy.$refs.identificationResultTable as any;
  $table.setCurrentRow(row);

  // 获取抗生素结果列表
  getASTResultList(row);
}
// 获取抗生素结果
function getASTResultList(row) {
  ASTRLoading.value = true;
  const url = '/api/bac/bac-drug-test-result/findBacDrugTestResultList';
  const data = {
    rptGroup: row.rptGroup,
    sampleda: row.sampleda + ' 00:00:00',
    sampleNo: row.sampleNo,
    isolateNum: row.isolateNum,
    testFlowNo: row.testFlowNo,
    testNodeNo: row.testNodeNo,
    isReport: 1
  };
  proxy.$http
    .get(url, { params: data })
    .then((res: any) => {
      drugTestResultList.push(...res.data);

      drugTestResultRowClick({ row: res.data[0], rowIndex: 0 });
      ASTRLoading.value = false;
    })
    .catch((err) => {
      proxy.$alert(err.data.error.message, '提示');
      ASTRLoading.value = false;
    });
}
// 行点击事件
function drugTestResultRowClick({ row, rowIndex }) {
  if (IsEmpty(row)) {
    return;
  }
  const $table = proxy.$refs.ASTResultTable as any;
  $table.setCurrentRow(row);
}
</script>
<style lang='scss' scoped>
@import '@/assets/css/isd-body.scss';

#crgResultComp {
  height: 100%;

  .crgResultCompTable {
    height: calc(100vh - 160px);
  }
}
</style>